package com.aop.controller;


import com.aop.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author wzm
 * @create 2023-10-11 16:09
 * project_name:stu_sys
 */
//演示Session存储数据在多次请求间共享
@RestController
@Slf4j
public class SessionController {

    //存储session
    @GetMapping("/addSession")
    public Result addSession(HttpSession session){
        log.info("Session：{}",session.hashCode());
        session.setAttribute("loginUser01","tom");//往session中存值
        return Result.success();

    }

    //获取session
    @GetMapping("/getSession")
    public Result getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        log.info("Session：{}",session.hashCode());
        Object list = session.getAttribute("loginUser01");
        log.info("session，{}",list);
        return Result.success(list);

    }

}

